import store from '../store'
import api from '../http/api.js'
import {
	mapGetters,
	mapState
} from 'vuex';
export default {
	data() {
		return {
			share: {
				title: '',
				imageUrl: '',
				path: ''
			},
		}
	},
	onShow() { //隐藏原生底部tabbar
		uni.hideTabBar();
	},
	onShareAppMessage(res) { //发送给朋友
		return {
			title: this.share.title,
			imageUrl: this.share.imageUrl,
			path: this.share.path,
		}
	},
	onShareTimeline(res) { //分享到朋友圈
		return {
			title: this.share.title,
			imageUrl: this.share.imageUrl,
			path: this.share.path,
			userInfo: '', //用户信息
		}
	},
	onAddToFavorites(res) { //收藏
		return {
			title: this.share.title,
			imageUrl: this.share.imageUrl,
			query: '',
		}
	},
	methods: {
		toPath(e, flag = 1) { //页面跳转
			if (flag == 1) {
				uni.navigateTo({
					url: e
				})
			} else if (flag == 2) {
				uni.switchTab({
					url: e
				})
			}
		},
		back(num = 1) { //返回
			if (getCurrentPages().length > 1) {
				uni.navigateBack({
					delta: num
				})
			} else {
				// 需要判断是什么角色
				uni.navigateTo({
					url: '/pages/index/index'
				});
			}
		},
		callPhone(e) { //拨打电话
			uni.makePhoneCall({
				phoneNumber: String(e)
			});
		},
		copy(e) { //复制
			uni.setClipboardData({
				data: String(e),
				success: (res) => {
					uni.$u.toast('复制成功')
				},
				fail: (err) => {
					uni.$u.toast('复制失败')
				}
			})
		},
		checkImg(e, num = 1) { //预览图片
			let arr = Array.isArray(e) ? e : e.split(',')
			uni.previewImage({
				current: num,
				urls: arr,
				longPressActions: {
					itemList: ['发送给朋友', '保存图片', '收藏'],
					success: (data) => {
						console.log(data);
					},
					fail: (err) => {
						console.log(err);
					}
				}
			});
		},
		getUserInfo() { //用户信息
			this.$api.getUserInfo().then(res => {
				if (res.code == this.status_code) {
					this.$store.commit('saveUserInfo', res.data)
					// this.$store.commit('saveToken', res.data.token)
				}
			})
		},
	},
	computed: {
		...mapState({
			zt_c: state => state.zt_c, //设置公共主题颜色
			token: state => state.token, //用户登录标识
			user: state => state.userInfo, //用户信息
			navh: state => state.navh, //高航兰高度
			btnh: state => state.btnh, //底部安全距离
			s_font: state => state.s_font, //系统字体大小
			pid: state => state.pid,//上级id
			status_code: state => state.status_code,//成功状态码
		}),
	},
	watch: {

	}
}